package com.zhangyu.eat.me;


import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;
import com.bumptech.glide.Glide;
import com.zhangyu.eat.R;
import com.zhangyu.eat.base.bean.Myuser;
import com.zhangyu.eat.login.view.LoaginActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment {


    @BindView(R.id.me_image)
    ImageView meImage;
    @BindView(R.id.me_nikename)
    TextView meNikename;
    @BindView(R.id.me_FX)
    ImageView meFX;
    @BindView(R.id.me_toolbar)
    Toolbar meToolbar;
    @BindView(R.id.me_collapsing)
    CollapsingToolbarLayout meCollapsing;
    @BindView(R.id._appbar)
    AppBarLayout Appbar;
    @BindView(R.id.me_unlogin)
    Button meUnlogin;

    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        meUnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AVUser.logOut();// 清除缓存用户对象
                AVUser currentUser = AVUser.getCurrentUser();// 现在的 currentUser 是 null 了
                getActivity().finish();
                startActivity(new Intent(getActivity(), LoaginActivity.class));
            }
        });


        String username = Myuser.getCurrentUser().getUsername();
        Myuser myuser=new Myuser();
        String nickName = myuser.getNickName();
//        Log.d("MeFragment", image);
//        meImage.setImageURI(Uri.parse(image));
        Glide.with(getActivity()).load(nickName).into(meImage);
        meNikename.setText(username);


    }
}
